﻿using System.Collections.Generic;
using System.Web.Mvc;
using System.Linq;
using VirtualTFS.BL;
using VirtualTFS.Core.Utility;
using VirtualTFS.DAL;
using VirtualTFS.DAL.Models;
using VirtualTFS.Models;
using System;
using VirutalTFS.Core.Utilities;

namespace VirtualTFS.Controllers
{
    public class TaskController : Controller
    {
        //
        // GET: /Task/

        public ActionResult Index()
        {
            return View();
        }

        public JsonResult GetViewModel()
        {
            var viewModel = new TaskViewModel
                {
                    Iterations =
                        Singleton<IterationImpl>.Instance.GetListIteration().Select(x => new IterationModel(x)).ToList(),
                    Users =
                        Singleton<AspnetUsersImpl>.Instance.GetListUsers().Select(x => new aspnet_UsersModel(x)).ToList(),
                    States =
                        Singleton<StatusParameterImpl>.Instance.GetListStates()
                                                      .Select(x => new StatusParameterModel(x))
                                                      .ToList()
                };
            var listBlock = new List<Block> {new Block {Id = 1, Name = "Block 1"}, new Block {Id = 2, Name = "Block 2"}};
            viewModel.Blocks = listBlock;
            viewModel.Areas = Singleton<AreaImpl>.Instance.GetListArea().Select(x=>new AreaModel(x)).ToList();
            var listActivities = new List<Activity>
                {
                    new Activity {Id = 1, Name = "Acc 1"},
                    new Activity {Id = 2, Name = "Acc 2"}
                };
            viewModel.Activities = listActivities;
            return Json(viewModel);
        }

        public bool CreateTask(TaskModel model)
        {
            model.Id = GuidUtils.NewSeqGuid();
            model.CreatedDate = DateTime.Now;
            model.ModifiedDate = DateTime.Now;
            model.Type = 1;
            var taskImpl = new TaskImpl();
            taskImpl.CreateTask(model);
            return true;
        }

        public bool UpdateTask(TaskModel model)
        {
            var taskImpl = new TaskImpl();
            taskImpl.UpdateTask(model);
            return true;
        }

        public ActionResult EditTask(int id)
        {
            return PartialView("TaskManagerLayout");
        }
    }
}
